package com.wy;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;

import sun.security.rsa.RSAKeyFactory;

public class JDBConnection {
	private Connection connection =null;
	private Statement st = null;
	private ResultSet rs = null;
	
	private String dbDriver = "org.gjt.mm.mysql.Driver";
	private String dbUrl = "jdbc:mysql://127.0.0.1:3306/db_wuliu?useUnicode=true&characterEncoding=utf-8";
	private String dbUser = "root";
	private String dbPwd = "root";
	
	public JDBConnection() {
		try {
			Class.forName(dbDriver).newInstance();
			try {
				connection = DriverManager.getConnection(dbUrl,dbUser,dbPwd);
			} catch (SQLException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
			System.out.println("�������سɹ�");
		} catch (InstantiationException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (IllegalAccessException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (ClassNotFoundException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}
	public ResultSet executeQuery(String sql) {
		try {
			st = connection.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,ResultSet.CONCUR_READ_ONLY);
			rs = st.executeQuery(sql); 
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return rs;
		
	}
	public boolean insert(String sql) {
		try {
			System.out.println("sql +"+sql);
			st = connection.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,ResultSet.CONCUR_READ_ONLY);
			System.out.println("爱国");
			
			int a = st.executeUpdate(sql);
			return a==1?true:false;
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return false;
		
	}
	public static void main(String[] args) throws SQLException {
		 ResultSet rs1=null;
		 String sql="update  tb_customer  set `password` = '123456'where Name='tx' and result = 'you dad'";
		 JDBConnection op=new JDBConnection();
		 op.insert(sql);
		 System.out.println(op.insert(sql));
//		 while(a.next()){
//		 System.out.println(a.getInt("Id"));
//		 }
	}


}
